var xmlHttp;

function verifyUsers() {
	document.getElementById('throbber-verify').style.visibility = 'visible';
	var url = "./utils/checkUsername.php";
	var params = '';
	if (document.getElementById("new_user_name")) {
		params = 'name=' + encodeURI(document.getElementById("new_user_name").value);
	}
	if(params.indexOf('&')>=0)
	{
		document.getElementById('throbber-verify').style.visibility = 'hidden';
		alert("user name can not contain '&'");
		return;
	}
	if(params.indexOf(';')>=0)
	{
		document.getElementById('throbber-verify').style.visibility = 'hidden';
		alert("user name can not contain ';'");
		return;
	}
	if(params.indexOf(':')>=0)
	{
		document.getElementById('throbber-verify').style.visibility = 'hidden';
		alert("user name can not contain ':'");
		return;
	}
	if(params.indexOf(',')>=0)
	{
		document.getElementById('throbber-verify').style.visibility = 'hidden';
		alert("user name can not contain ','");
		return;
	}
	
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert ("Browser does not support Http Request");
		return;
	}

	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
	xmlHttp.onreadystatechange = stateChanged;
}

function stateChanged() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		var rsp = xmlHttp.responseText;

		if (document.getElementById("divMsg")) {
			document.getElementById("divMsg").innerHTML = rsp;
		}
		document.getElementById('throbber-verify').style.visibility = 'hidden';
	}
}

function GetXmlHttpObject() {
	var xmlHttp = null;

	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
